package com.example.labapp;

import android.content.Context;
import android.content.Intent;
import android.os.strictmode.CleartextNetworkViolation;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import androidx.collection.ArraySet;
import androidx.recyclerview.widget.RecyclerView;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.List;

public class examItemAdapter extends BaseAdapter {
    public static class examItemData {
        public String title;
        public float Grade;
        public int Num;
    }

    private ArrayList<examItemData> data=new ArrayList<>();
    private LayoutInflater layoutInflater;
    private final Context context;

    private String studName;

    public examItemAdapter(Context context_) {
        context = context_;
    }

    private static class Info {
        public TextView title;
        public TextView grade;
        public TextView FinishNum;
    }

    public void AddItem(examItemData newItem)
    {
        data.add(newItem);
    }

    public void updateUI()
    {
        notifyDataSetChanged();
    }

    public examItemData getItemTitle(int position)
    {
        return data.get(position);
    }

    @Override
    public int getCount()
    {return data.size();}

    @Override
    public Object getItem(int position)
    {
        return data.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        Info infoHolder=null;
        if(convertView==null)
        {
            convertView=layoutInflater.from(context).inflate(R.layout.exam_select_item,parent,false);
            infoHolder=new Info();
            infoHolder.title=(TextView) convertView.findViewById(R.id.examSelectItemTitle);
            infoHolder.grade=(TextView) convertView.findViewById(R.id.examSelectItemGrade);
            infoHolder.FinishNum=(TextView) convertView.findViewById(R.id.examSelectItemNum);
            convertView.setTag(infoHolder);
        }
        else
        {
            infoHolder=(Info) convertView.getTag();
        }
        infoHolder.title.setText(data.get(position).title);
        infoHolder.grade.setText(String.format("分数: %.1f",data.get(position).Grade));
        infoHolder.FinishNum.setText(String.format("作答次数:%d",data.get(position).Num));
        return convertView;
    }
}
